import { API_ENDPOINT } from '@/config'
import { useUserStore } from '@/stores/auth'
import { ClientOptions, defaultExchanges } from '@urql/vue'
//websocket 客户端
//const subscriptionClient = new SubscriptionClient(WS_URL, {reconnect: true});
//urql 客户端
export const urqlOptions: ClientOptions = {
  url: API_ENDPOINT,
  fetchOptions: () => {
    const userStore = useUserStore()
    return {
      headers: {
        authorization: userStore.token ? `Bearer ${userStore.token}` : ''
      }
    }
  },
  exchanges: [
    ...defaultExchanges
    // subscriptionExchange({
    //     forwardSubscription: (operation) => subscriptionClient.request(operation),
    // }),
  ]
}
